package com.reyco1.medusa.display.container
{
	import flash.display.DisplayObject;
	import flash.events.Event;

	public class VBox extends Container
	{
		public static const LEFT:int   = 1;
		public static const CENTER:int = 2;
		public static const RIGHT:int  = 3;
		public static const NONE:int   = 0;
		
		private var _alignMode:int = 0;
		
		public function VBox()
		{
			super();
		}
		
		override protected function build():void
		{
			var ypos:Number = 0;
			var xpos:Number = 0;
			var child:DisplayObject;
			var i:int;
			_width = 0;
			_height = 0;
			
			for(i = 0; i<numChildren; i++)
			{
				child = getChildAt(i);
				child.y = ypos;
				child.x = xpos;
				ypos += child.height + gap;
				_width = Math.max(_width, child.width);
				_height += child.height;
			}
			
			for(i = 0; i<numChildren; i++)
			{
				child = getChildAt(i);
				
				switch(alignMode)
				{
					case 1:
						child.x = 0;
						break;
					
					case 2:
						child.y = _width * 0.5 - child.width * 0.5;
						break;
					
					case 3:
						child.x = _width - child.width;
						break;
				}
			}
			
			_height += gap * (numChildren - 1);
			
			dispatchEvent(new Event(Event.RESIZE));
		}

		public function get alignMode():int
		{
			return _alignMode;
		}

		public function set alignMode(value:int):void
		{
			_alignMode = value;
			invalidate();
		}

	}
}